package com.rybbaby.tss.front.tssClassAttendance.service.imp;

import com.rybbaby.tss.core.utils.SequenceUtil;
import com.rybbaby.tss.core.utils.StringUtils;
import com.rybbaby.tss.core.web.service.imp.BaseServiceImp;
import com.rybbaby.tss.front.tssClassAttendance.dao.ITssClassAttendanceDao;
import com.rybbaby.tss.front.tssClassAttendance.entity.TssClassAttendance;
import com.rybbaby.tss.front.tssClassAttendance.service.ITssClassAttendanceService;
import com.rybbaby.tss.front.tssClassesLessons.dao.ITssClassesLessonsDao;
import com.rybbaby.tss.front.tssClassesLessons.entity.TssClassesLessons;
import com.rybbaby.tss.front.tssMemberCheckAttendance.entity.TssMemberCheckAttendance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @description �������ݿ��������ʵ��
 * 
 * @author �״���
 * 
 * @createDate 2017-09-20 ����5:57:00
 */
@Service
@Transactional
public class TssClassAttendanceServiceImp extends BaseServiceImp<TssClassAttendance>  implements ITssClassAttendanceService {

    @Autowired
    private ITssClassAttendanceDao tsClassAttendanceDao;
    @Autowired
    private ITssClassesLessonsDao tssClassesLessonsDao;
    @Override
    public int updateClassAttendance(String lessonsId,int classAttendance) {
        return tsClassAttendanceDao.updateClassAttendance(lessonsId,classAttendance);
    }

    @Override
    public boolean saveEntity(String targetDataId) throws Exception {
        boolean bool = true;
        String ss[] = StringUtils.split(targetDataId, ",");
        List<TssClassAttendance> tssClassAttendanceArrayList = new ArrayList<>();
        for (String s1 : ss) {
            TssClassesLessons tssClassesLessons = tssClassesLessonsDao.get(TssClassesLessons.class, s1);
            TssClassAttendance tssClassAttendance = new TssClassAttendance();

            tssClassAttendance.setId(SequenceUtil.getUpperCaseUUID());
            tssClassAttendance.setAttendanceStatus(1);
            tssClassAttendance.setClassId(tssClassesLessons.getClassId());
            tssClassAttendance.setCreateTime(new java.sql.Timestamp(System.currentTimeMillis()));

            tssClassAttendanceArrayList.add(tssClassAttendance);
        }
        return tsClassAttendanceDao.jdbcBatchSave(tssClassAttendanceArrayList);
    }
}
